import FlowModelInstance from '@/components/flow/typs/FlowModelInstance.js';
import {Modal} from 'ant-design-vue';
import Vue from 'vue';

export default class DeleteNodeCommand {
  supportInstance;
  nodeId;

  constructor(supportInstance, nodeId) {
    this.supportInstance = supportInstance;
    this.nodeId = nodeId;
  }

  serve() {
    Vue.use(Modal);
    Modal.confirm({
      okText: '确定',
      cancelText: '取消',
      title: '确定删除吗',
      okText: '确定',
      cancelText: '取消',
      content: '删除后不可恢复，确定删除吗',
      onOk: () => {
        let flowModelInstance = new FlowModelInstance(this.supportInstance.getModel());
        flowModelInstance.removeNodeByIdAndTrim(this.nodeId);
        this.supportInstance.setModel(flowModelInstance.getModelString());
      },
    });
  }
};
